package server.utilities;

/**
 * All errors that may occur when uploading a file. A error is made of a code and an associated message
 * @author Romain Pellerin
 */
public enum UploadMessage {
	
	SUCCESS(0,"File successfully uploaded"),
	DIRECTORY_ERROR(1,"The file can't be saved on disk (directory is missing?)"),
	FILE_TOO_SMALL(2,"File is either missing or too small. 1MB is required at least."),
	FILE_TOO_BIG(3,"File is too big, 2500MB is the maximum accepted"),
	FILE_MISSING(4,"File is missing"),
	UPLOAD_ABORTED(5,"Upload has be aborted (unknown reason)"),
	USER_UNKNOWN(6,"You seems to be disconnected. Try refreshing the page."),
	NO_ENOUGH_SPACE_AVAILABLE(7,"Insufficient disk space (2MB free space are needed at least)"),
	LINK_INVALID(8,"Error with your link. It seems not valid."),
	LINK_SUCCESS(9,"URL successfully uploaded"),
	NOT_A_POST(10,"Request is not a POST request");
	
	/**
	 * Get the error's code
	 * @return The code
	 */
	public int getCode() {
		return code;
	}

	/**
	 * Get the error's associated message
	 * @return The message
	 */
	public String getMessage() {
		return message;
	}
	
	/**
	 * Get the error's associated message
	 * @param code The code of the message you're looking for
	 * @return The associated message, or null if it doesn't exists
	 */
	public static String getMessage(int code) {
		for (UploadMessage error : UploadMessage.values()) {
			if (error.code == code) return error.getMessage();
		}
		return null;
	}

	private int code;
	private String message;
	
	UploadMessage(int code, String message) {
		this.code = code;
		this.message = message;
	}
}
